class code4 {
    //a1b3c2拼凑
    public List<List<String>> groupAnagrams(String[] strs) {

        Map<String,List<String>> map = new HashMap<>();
        for(String ss:strs) {
            int[] count = new int[26];
            for(int i=0;i<ss.length();i++) {
                count[ss.charAt(i) - 'a']++;
            }

            StringBuffer sb = new StringBuffer();
            for(int i = 0; i < 26; i++) {
                if(count[i] != 0) {
                    sb.append((char)('a' + i));
                    sb.append(count[i]);
                }
            }
            String key = sb.toString();
            List<String> list = map.getOrDefault(key,new ArrayList<String>());
            list.add(ss);
            map.put(key,list);
        }
        return new ArrayList<List<String>>(map.values());
    }
}